package com.yudean.esb.plugins;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 用来处理数据库返回数据，并将其转换为字符串类型
 *
 * @author Lei Duan <duanlei#gdyd.com>
 * @version 1.0.0
 * @since 2013-10-30@10
 */
public class DbTypeHandler {
    private final static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    /**
     * 将字段数据转换成字符串
     *
     * @return 转换后的字符串
     */
    public static String getValue(Object obj) {
        if (obj == null) return "";
        if (obj instanceof BigDecimal) {
            BigDecimal val = (BigDecimal) obj;
            return val.toString();
        } else if (obj instanceof Date) {
            Date val = (Date) obj;
            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
            return sdf.format(val);
        } else {
            return obj + "";
        }
    }

}